<?php
/**
 * 优惠卷
 * @author tangbl
 *
 */
class YhjAction extends CommonAction{
	/**
	 * 非场景使用,未过期优惠卷列表
	 */
	public function index() {	
		$json = D("Actyhj")->getCouponList();
		$this->assign("list",$json);

		$this->display();
	}
	
	/**
	 * 非场景使用,未过期优惠卷详情
	 */
	public function detail() {
		
		if(!$_SESSION[C('USER_AUTH_KEY')]){
			redirect(U(C('USER_AUTH_GATEWAY')));
		}
		
		$id = $this->_param("id","intval",0);
		
		$user = getMember();

		if(IS_POST){
			
			$map['yhjid']  = $id;
			$map['userid'] = session(C('USER_AUTH_KEY'));
			$map['mobile'] = session(C('USER_AUTH_ACCOUNT'));
			$json = sendRest("Coupon/get", $map);
			if($json['status'] == 1){
				$this->success("领取优惠卷成功",U("Member/coupon_index"));
			}else{
				$this->error($json['info'],U("Yhj/index"));
			}
			
		}else{
		
			$json = D("Actyhj")->getCouponDetail($id);
			
			if($json['status'] == 1){
				$this->assign("detail",$json);
				$this->display();
			}else{
				$this->error("优惠卷不存在",U("Yhj/index"));
			}
		}
	}
	
	
	
}
?>